<template>
  <div class="musiclist">
    <div class="list-item"
         v-for="(item,index) in artistList"
         :key="index"
         @click="enterArtistDetail(item)">
      <img :src="getImgUrl(item)"
           alt=""
           @load="imgLoad">
      <div class="title">{{item.name}}</div>
    </div>
  </div>
</template>

<script>
import { imgLoadMixin } from 'assets/common/mixin'
export default {
  name: 'ArtistList',
  props: {
    artistList: {
      type: Array,
      default () {
        return []
      }
    }
  },
  mixins: [imgLoadMixin],
  methods: {
    getImgUrl (item) {
      return item.picUrl || item.coverImgUrl;
    },
    imgLoad () {
      // 判断已经加载的图片是否与这个需要渲染的数组中的图片一样，一致，则渲染页面
      if (this.imgCount === this.artistList.length) this.$emit("imgLoad");
      this.imgCount++;
    },
    enterArtistDetail (item) {
      this.$router.push('/artist/' + item.id);
    }
  }
}
</script>

<style scoped>
.musiclist {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  color: #000;
}
.musiclist .list-item {
  position: relative;
  margin: 5px 6px;
  width: 150px;
  padding-bottom: 10px;
  font-size: 13px;
}
.list-item img {
  width: 100%;
}
</style>
